Learn Red by Ivo Balbaert

Learn Red by Ivo Balbaert

Author:Ivo Balbaert
Language: eng
Format: epub
Tags: COM051000 - COMPUTERS / Programming / General, COM051230 - COMPUTERS / Software Development and Engineering / General, COM083000 - COMPUTERS / Security / Cryptography
Publisher: Packt Publishing
Published: 2018-05-18T10:48:37+00:00


The does word

The simplest way to make your own function in Red is with the does word. Consider the following code:

;-- see Chapter06/do-does-has-func.red:

cls: does [ loop 100 [print newline] ] ; == func [][loop 100 [print newline]]

cls ; call function cls

The newline phrase is the character that prints a new line.

In the preceding example, we create a function called cls that clears the output screen by printing 100 blank lines when it is called as cls. It is a function (func), as we can see from the return value when defining cls. You use does when you need a function that has no arguments and no local variables.

=> Now answer question 2 from the Questions section.

An important distinction should be made between the following two kinds of variables:

Local variables, which are only known in the function body itself

Global variables, which are known in the function as well as outside of it



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.